/*package com.smarttest.portal.service.timertask;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smarttest.portal.mapper.InterfacelistMapper;
import com.smarttest.portal.pojo.Checkinterface;
import com.smarttest.portal.pojo.Interfacelist;
import com.smarttest.portal.pojo.InterfacelistExample;
import com.smarttest.portal.service.CheckInterfaceService;
import com.smarttest.portal.service.timertask.util.APIQueryUtil;


@Service
public class InterfaceStability {
	private final Logger logger = Logger.getLogger(getClass());
	@Autowired
	private CheckInterfaceService checkInterfaceService;
	
	@Autowired
	private InterfacelistMapper listmapper;

	@Value("${alarmnum}")
	private String alarmnum = "13408517677";
	@Value("${runtimertask:false}")
	private String runtimertask = "false";

	private static final Logger log = Logger
			.getLogger(InterfaceStability.class);
	private ScheduledExecutorService scheduledExecutorService = Executors
			.newSingleThreadScheduledExecutor();

	@PostConstruct
	public void init() {
		regMap.put("startDate", "\""+startDate+"\"");
		regMap.put("endDate", "\""+endDate+"\"");
		regMap.put("startDay", "\""+startDay+"\"");
		regMap.put("endDay", "\""+endDay+"\"");
		regMap.put("orgcode", "\""+orgcode+"\"");
		regMap.put("orgcode2", "\""+orgcode2+"\"");
		regMap.put("sysId", "38");
		
		regMap.put("truckId", "\""+truckId+"\"");
		regMap.put("trucknum", "\""+trucknum+"\"");
		
		if (StringUtils.equalsIgnoreCase("true", runtimertask)) {
			log.info("InterfaceAction init-" + Thread.currentThread().getName());
			scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {

				@Override
				public void run() {
					queryAPI();
				}
			}, 0, 1, TimeUnit.MINUTES);
		}
	}

	private static String txRootUrl = "http://tx.router.huoyunren.com/router/rest";
	private static String apiRootUrl = "http://api.huoyunren.com/router/rest";
	public static String imei = "107015090000007";
	public static String gpsno = "90000007";
	public static String orgcode = "200ILV01";
	public static String orgcode2 = "20000G";
	public static String trucknum = "385095883DC1CE6E036B3677174B192C81";
	public static String truckId = "C4DE2CE60A91AAE94C664714B1B27E3D";
	private Calendar cal = Calendar.getInstance();
	private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	private SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMdd");
	public String startDay = df2.format(cal.getTime());
	public String endDay = df2.format(cal.getTime());
	public String startDate = df.format(cal.getTime()) + " 00:00:00";
	public String endDate = df.format(cal.getTime()) + " 23:59:59";
	Map<String, String> regMap = new HashMap<>();
	
	

	public static void main(String[] args) {

	}

	private void queryAPI() {
		List<Interfacelist> result;
		InterfacelistExample ex = new InterfacelistExample();
		
		result = listmapper.selectByExample(ex);
		
		Iterator<Interfacelist> iter = result.iterator();
		
		String urlpre = "";
		APIQueryUtil apiSearchTest = null;
		
		while(iter.hasNext()){
			Interfacelist inter = iter.next();
			String url = inter.getUrl();
			String method = inter.getMethod();
			String param = inter.getParameter();
			String realparm = simpleTemplate(param, regMap, "");
			
			System.out.println(realparm);
			
			if (apiSearchTest == null || !(urlpre.equals(url))){
				apiSearchTest = new APIQueryUtil(url);
				apiSearchTest.setAlarmnum(alarmnum);
			}
			urlpre = url;
			
			try{
				@SuppressWarnings("unchecked")
				Map<String,Object> para = (Map<String, Object>) JSON.parse(realparm);
				JSONObject resultJson = apiSearchTest.doAPIUrl(method, para);
				System.out.println(resultJson.toJSONString());
				save2DB(method, resultJson);
			}catch(Exception e) {
				e.printStackTrace();
			}
		}
	}

	private void save2DB(String method, JSONObject resultJson) {
		Checkinterface checkinterface = new Checkinterface();
		checkinterface.setCode(resultJson.getIntValue("code"));
		checkinterface.setMessage(resultJson.getString("message"));
		checkinterface.setTime(resultJson.getIntValue("time"));
		checkinterface.setCount(1);
		checkinterface.setMethod(method);
		checkinterface.setUpdatetime(new Date());
		checkinterface.setCreatetime(new Date());
		int insert = checkInterfaceService.insert(checkinterface);
		logger.info("save2DB:" + insert + ",method:" + method + ",resultJson:"
				+ resultJson);
	}
	
	//字符串替换函数，用于替换字符串变量
	public static String simpleTemplate(String templateStr, Map<String, ?> data, String... defaultNullReplaceVals) {  
	    if(templateStr == null) return null;  
	      
	    if(data == null) data = Collections.EMPTY_MAP;  
	          
	    String nullReplaceVal = defaultNullReplaceVals.length > 0 ? defaultNullReplaceVals[0] : "";  
	    Pattern pattern = Pattern.compile("\\$\\{([^}]+)}");  
	          
	    StringBuffer newValue = new StringBuffer(templateStr.length());  
	  
	    Matcher matcher = pattern.matcher(templateStr);  
	  
	    while (matcher.find()) {  
	        String key = matcher.group(1);  
	        String r = data.get(key) != null ? data.get(key).toString() : nullReplaceVal;  
	        matcher.appendReplacement(newValue, r.replaceAll("\\\\", "\\\\\\\\")); //这个是为了替换windows下的文件目录在java里用\\表示  
	    }  
	  
	    matcher.appendTail(newValue);  
	  
	    return newValue.toString();  
	}  

}
*/